<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!-- <style type="text/css">
#add_supply_aggrement_info .box p>label>span {
	display: inline-block;
	width: 80px;
	text-align: right;
}

#add_supply_aggrement_info  .formBox {
	padding: 0;
}
#add_supply_aggrement_info input[type='file']{
	display:none;
}

#add_supply_aggrement_info .longWidth{
	width:580px;
}

</style> -->
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
<div class="modal fade" id="add_supply_aggrement_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 750px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新增供货协议</h4>
			</div>
			<form id="add_supply_aggrement_form" enctype="multipart">
				<input type="hidden" name="firstid" id="firstid">
				<div class="box modal-body">
					<p>
							<label class="must">协议代码</label>
							<input type="text" readonly placeholder="自动生成" class="form-control"></input>
							<label class="must">供应商</label>
							<select name="supplierid" id="supplierid" class="form-control select">
								<c:forEach items="${supplierlist }" var="supplier">
									<option value=${supplier.supplierid }>${supplier.chinesename }</option>
								</c:forEach>
							</select>
					</p>
					<p>
							<label class="must">协议说明</label>
							<input type="text"  name="protocolexplain" id="protocolexplain" class="form-control"></input>
					</p>
					<p>
							<label class="must">协议状态</label>
							<select id="protocostatus" name="protocostatus" class="form-control select">
								<option value="可用">可用</option>
								<option value="不可用">不可用</option>
							</select>
							<label class="must">生效时间</label>
							<input type="text" name="starttimestr" id="starttime" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>~
							<input type="text" name="endtimestr" id="endtime" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="form-control"></input>
					</p>
					<p>
						<label for="supplyAgreementAnnex">
							<span>协议附件:</span>
							<a id="supplyAgreementAnnexName" style="width:580px;text-align:left;color:#2b7dbc;cursor:pointer;">选择文件</a>
							<input type="file" id="supplyAgreementAnnex" name="supplyagreementannex" onchange="chooseAnnex();" ></input>
						</label>
					</p>
				</div>
			</form>
			<div class="red" id="add_supply_aggrement_msg" style="text-align:center;"></div>
			<div class="modal-footer">
				<button type="button"  onclick="saveAddSupplyAgreement();" class="btn btn1">保存</button>
				<button type="button"  data-dismiss="modal" class="btn btn1">取消</button>
			</div>
		</div>
	</div>
</div>
<script>

function addSupplyAgreement(){
	$('#add_supply_aggrement_info :text').val("");
	$("#add_supply_aggrement_info select").val("");
	$('#add_supply_aggrement_info').modal('show');
}

function saveAddSupplyAgreement(){
	
	if(!validateAddForm()) return ;//校验
	
    var formData = new FormData($("#add_supply_aggrement_form")[0]);  
	$.ajax({
		url:"<%=basePath %>supplyagreement/add.do",
		type:"post",
		async : false,
		dataType:"json",
        contentType: false,  
        processData: false,  
		data : formData,
		success:function(data){
			if(data.result=="success"){
				$("#add_supply_aggrement_msg").html("");
				$('#add_supply_aggrement_info :text').val("");
				$("#add_supply_aggrement_info select").val("");
				$('#add_supply_aggrement_info').modal('hide');
				location.href=location.href;
			}else{
				$("#add_supply_aggrement_msg").html("新增供货协议失败：",data.error);
			}
		},
		error :function(){
			$("#add_supply_aggrement_msg").html("新增供货协议失败！")
		}
	});
}

function chooseAnnex(){
	var annex=$("#supplyAgreementAnnex").val();
	var arr=annex.split('\\');
    var fileName=arr[arr.length-1];
	if(annex==""){
		$("#supplyAgreementAnnexName").html("选择文件")
	}else{
		$("#supplyAgreementAnnexName").html(fileName)
	}
}
//供货协议校验
function validateAddForm(){
	
	if(!validateSelect("供应商","#add_supply_aggrement_info [name='supplierid']",false)){
		return false;
	} 
	
	if(!validateString("协议说明","#add_supply_aggrement_info [name='protocolexplain']",198,false)){
		return false;
	}
	
	if(!validateSelect("协议状态","#add_supply_aggrement_info [name='protocostatus']",false)){
		return false;
	}
	
	
	if(!validateString("生效时间","#add_supply_aggrement_info [name='starttimestr']",120,false)){
		return false;
	}
	
	if(!validateString("生效时间","#add_supply_aggrement_info [name='endtimestr']",120,false)){
		return false;
	}
	return true;
}

</script>